// pages/Dubbing/Dubbing.js
import api from "../../utils/api"
Page({
    /** 页面的初始数据
     */
    data: {
        avatar: '../../image/order/model.png',
        objectArray: [{
            id: 1,
            name: '#19'
        }, {
            id: 2,
            name: '#20'
        }, {
            id: 3,
            name: '#21'
        }, {
            id: 4,
            name: '#22'
        }],
        index: -1,
        name: ""
    },
    bindToCamera(e) {
        console.log(123)
        wx.navigateTo({
            url: '/pages/camera/camera',
        })
    },
    bindPickerChange(e) {
        console.log(e.detail.value)
        this.setData({
            index: e.detail.value
        })
    },
    bindNameChange(e) { },
    postUser(e) {
        console.log("===============")
        console.log(this.data.name)
        console.log(this.data.objectArray[this.data.index].id)
        console.log("==================")
        wx.showLoading({
            title: '提交中',
            mask: true
        })
        wx.uploadFile({
            url: api.bank,
            filePath: this.data.avatar,
            name: 'avatar',
            formData: {
                'name': this.data.name,
                'area': this.data.objectArray[this.data.index].id
            },
            success(res) {
                var dataDict = JSON.parse(res.data)
                var row = {
                    id: dataDict.id,
                    area: dataDict.area_text,
                    name: dataDict.name,
                    avatar: dataDict.avatar,
                }
                var pages = getCurrentPages();
                var prevPage = pages[pages.length - 2]; //上-个页面
                prevPage.addRow(row)
                wx.navigateBack({})
            },
            complete() {
                wx.hideLoading()
            }
        })
    }
})